<#import "/spring.ftl" as spring />
<html>
<head>
	<title>Referring realtors</title>
</head>
<body>

<script src="${springMacroRequestContext.contextPath}/js/prototype.js" type="text/javascript"></script>
<script src="${springMacroRequestContext.contextPath}/js/scriptaculous/scriptaculous.js" type="text/javascript"></script>

<#if realtors??>
	<script>
	//Builds out the list of realtors for the autocomplete textfield
	var realtorsList = [
	  <#list realtors as realtor>
	    '${realtor.name.last}, ${realtor.name.first}<#if realtor.company??> - ${realtor.company!}</#if>'<#if realtor_has_next>,</#if>
	  </#list>
	];
	</script>
</#if>

<div id="content">
	<h1>REFERRING REALTORS</h1>
	
	<p>Below you'll find a list of realtors associated with your company.  They were either added by you and your coworkers,
	or by a Home Buyer while scheduling an inspection.</p>
	
	<p>Please click on a name to edit a realtor's information, or click "ADD REALTOR" to enter a new one.</p>
	
	<#if realtors?size gt 10>
	<script>
		//hide the auto-selector from non-javascript browsers
		document.write('<p>Or you can quickly find an existing agent by typing in the agent\'s name in the textfield below. </p>');
		document.write('<div style="float: right; margin: 10px 0 10px 0;">');
		document.write('<form name="quickEdit" action="editReferringRealtor.html">');
		document.write('<input id="referringAgentSelection" name="selectedRealtorName" autocomplete="off" type="text" value="" style="width: 150px;"/>');
		document.write('<div class="autocomplete" id="realtorsDropDown" style="display:none"></div>');
		document.write('<input type="submit" value="edit" style="color: #004071; margin-left: 5px;" />');
		document.write('</form>');
		document.write('</div>');
		document.write('<br style="clear:both">');
		new Autocompleter.Local('referringAgentSelection', 'realtorsDropDown', realtorsList, {frequency:0.1});
	</script>
	</#if>
	
	<table class="standard">
		<tr>
			<th>NAME</th>
			<th>COMPANY</th>
			<th>PHONE</th>
			<th>EMAIL</th>
		</tr>
		<#if realtors?? && realtors?size gt 0>
			<#list realtors as realtor>
			<tr>
				<td class="rowHeader">
					<a href="editReferringRealtor.html?id=${realtor.id}">
						${(realtor.name.first?upper_case)!}
						${(realtor.name.last?upper_case)!}
						<#-- temp hack so that we can delete empty realtor objects --><#if realtor.name.first?length = 0>n/a</#if>
					</a>
				</td>
				<td>${(realtor.company?upper_case)!}</td>
				<td>${(realtor.cellPhone?upper_case)!}</td>
				<td>${(realtor.email?upper_case)!}</td>
			</tr>
			</#list>
		<#else>
			<tr>
				<td colspan="5">YOU HAVE NOT ADDED ANY REALTORS</td>
			</tr>
		</#if>
	 </table>
	 
	 <p><a href="<@spring.url "/inspector/editReferringRealtor.html" />" class="formLink">-ADD REALTOR-</a>
	 <a href="settings.html" class="formLink">-CANCEL-</a></p>

</div>
</body>
</html>
